<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电子时钟</title>
    <style>
        body {
            background-color: aqua;
        }
        #house {
            font-size: 30px;
            color: rgb(13, 169, 34);
            float: right;
        }
        .box1 {
            overflow: hidden;
        }
        #calculator {
            width: 200px;
            font-family: Arial, sans-serif;
            margin: 0 auto;
        }

        #display {
            width: 100%;
            padding: 10px;
            font-size: 20px;
            box-sizing: border-box;
            text-align: right;
        }

        .buttons {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 5px;
        }

        .buttons button {
            padding: 10px;
            font-size: 18px;
            border: none;
            background-color: #f2f2f2;
            cursor: pointer;
        }

        .buttons .operator {
            background-color: #ddd;
        }

        .buttons button:hover {
            background-color: #ddd;
        }

        .buttons .operator:hover {
            background-color: #ccc;
        }
        .clock-display {
            font-family: Arial, sans-serif;
            font-size: 36px;
            text-align: center;
            margin-top: 50px;
        }
    </style>
</head>
<body>
    <div class="box1">
        <a href="https://gitee.com/Kiryu-L/jntm" id="house" target="_blank">仓库</a>
    </div>
    <div id="clock-display" class="clock-display"></div>
    <button>暂停</button>
    <button>恢复</button>
    <script>
        const btn = document.querySelectorAll('button')
        let falg = true
        function updateClockDisplay() {
            const now = new Date();
            const hours = String(now.getHours()).padStart(2, '0');
            const minutes = String(now.getMinutes()).padStart(2, '0');
            const seconds = String(now.getSeconds()).padStart(2, '0');

            const clockDisplay = document.getElementById('clock-display');
            clockDisplay.textContent = `${hours}:${minutes}:${seconds}`;
        }
        
        // 初始化并设置定时器
        updateClockDisplay();
        let time = setInterval(updateClockDisplay, 1000);
        btn[0].addEventListener('click',() => {
            clearInterval(time)
            falg = false
        })
        btn[1].addEventListener('click',() => {
            if(falg == false) {
                updateClockDisplay();
                time = setInterval(updateClockDisplay, 1000);
                falg = true
            } else {
                alert('当前没有暂停')
            }
        })
    </script>
    <div id="calculator">
        <input type="text" id="display" readonly>
        <div class="buttons">
            <button class="operator" value="+">+</button>
            <button class="operator" value="-">-</button>
            <button class="operator" value="*">*</button>
            <button class="operator" value="/">/</button>
            <button value="7">7</button>
            <button value="8">8</button>
            <button value="9">9</button>
            <button value="C">C</button>
            <button value="4">4</button>
            <button value="5">5</button>
            <button value="6">6</button>
            <button value="=">=</button>
            <button value="1">1</button>
            <button value="2">2</button>
            <button value="3">3</button>
            <button value="0">0</button>
            <button value=".">.</button>
        </div>
    </div>
    <script>
        document.querySelector('#calculator').addEventListener('click', function(event) {
            const target = event.target;
            if (target.tagName === 'BUTTON') {
                const display = document.querySelector('#display');
                const value = target.value;

                if (value === 'C') {
                    display.value = '';
                } else if (value === '=') {
                    try {
                        display.value = eval(display.value);
                    } catch (error) {
                        display.value = 'Error';
                    }
                } else {
                    display.value += value;
                }
            }
        });
    </script>
</body>
</html>